const db = require('../../../libs/db.config');
// 使用bcryptjs进行加密
const bcrypt = require('bcryptjs')
// 生成随机id
const crypto = require('crypto');

module.exports = async (data) => {
    const { userName, password, phone } = data;
    // bcrypt加密
    const passwordBcrypt = bcrypt.hashSync(password, 10)
    const searchSQL = `insert into user set ?`;
    const randomId = crypto.randomBytes(16).toString('hex');
    let params = {}
    params.userName = userName
    params.password = passwordBcrypt
    params.phone = phone
    params.userID = randomId
    return await db.query(searchSQL, params);
};